package com.my.test.user.aop;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class DaoAop {

	@Pointcut("execution(* com.my.test.user.dao.*.*(..))")
    private void httpUtilAspectPointCut(){};

    @Before("httpUtilAspectPointCut()")
    public void before()  {
    }

    @Around("httpUtilAspectPointCut()")
    public Object around(ProceedingJoinPoint point) throws Throwable {
        Object result = null;
        MethodSignature signature = (MethodSignature) point.getSignature();
        Class<?>[] classz = point.getTarget().getClass().getInterfaces();  
        String sqlid = classz[0].getName()+"."+signature.getMethod().getName();  
        long start = System.currentTimeMillis();
        result = point.proceed();
        System.out.println(sqlid+"查询数据库,耗时："+(System.currentTimeMillis()-start)+"毫秒");
        return result;
    }

    @After("httpUtilAspectPointCut()")
    public void after()  {
    }
}
